﻿var obj = {
    value: 0,
    increment: function () {
        this.value += 1;
    }
};

obj.increment(); //Method invocation


var value = 500; //Global variable
var obj = {
    value: 0,
    increment: function () {
        //var that = this;
        this.value++;
        
        var innerFunction = function () {
            alert(this.value);
        }

        innerFunction(); //Function invocation pattern
    }
}
//obj.increment(); //Method invocation pattern

var Cheese = function (type) {
    var cheeseType = type;
    return cheeseType;
}

cheddar = new Cheese("cheddar"); //new object returned, not the type.

var add = function (num1, num2) {
    return num1 + num2;
}

var array = [3, 4];
add.apply(null, array); //7



var calculateSum = function () {
    var result = 0;
    for (var i = 0; i < this.values.length; i++) {
        result += this.values[i];
    }
    return result;
}

var person1 = {
    name: 'Nick',
    values: [1, 3, 8, 10]
}

var person2 = {
    name: 'Coral',
    values: [3, 1, 19, 5, 83]
}

console.log(calculateSum.apply(person1));
console.log(calculateSum.apply(person2));

//var data = 'asdfasd';
var displayData = function () {
    alert(this.data);
}

//displayData(); //undefined
//displayData.apply(obj); //Hello World
//var someArray = ['nick', 'Hello World'];
//displayData.apply(obj, someArray);


var someArray = [[]];

var jeopardy = [[100, 200, 300, 400, 500], [100, 200, 300, 400, 500], [100, 200, 300, 400, 500]];

var books = [[{ title: 'Book 1', author: 'Author 1' }, { title: 'Book 6', author: 'Author 6' }], [{ title: 'Book 3', author: 'Author 3' }], [{ title: 'Book 4', author: 'Author 4' }, { title: 'Book 1', author: 'Author 1' }, { title: 'Book 3', author: 'Author 3' }]]


for (var i = 0; i < books.length; i++) {
    var newStep = i;
    for (var j = 0; j < books[i].length; j++) {
        if (newStep == i) {
            console.log('New Book List');
            newStep = -1;
        }
        for (var x in books[i][j]) {
            console.log(x + ': ' + books[i][j][x]);
        }
    }
}